; (function () {

    function createXHR() {
        if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        }
        return new ActiveXObject("Msxml2-XMLHTTP");
    }

    function getParams(obj) {
        var str = "";
        for (const key in obj) {
            str += key + '=' + obj[key] + "&";
        }
        return str;
    }

    $.extend({
        myAjax(settings) {
            settings.async = settings.async == undefined ? true : settings.async;
            settings.type = settings.type == undefined ? "get" : settings.type;
            settings.dataType = settings.dataType == undefined ? "json" : settings.dataType;

            return new Promise((resolve, reject) => {


                var xhr = new createXHR();
                if (settings.type == "type") {
                    xhr.open("get", settings.url + "?" + getParams(settings.data), settings.async)
                    xhr.responseType = "json";
                    xhr.send(null)
                } else {
                    xhr.open("post", settings.url, settings.async);
                    xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
                    xhr.responseType = "json";
                    xhr.send(settings.data);
                }

                xhr.onreadystatechange == function () {
                    if (xhr.status == 200 && xhr.readyState == 4) {
                        if (typeof (settings.success) == "function") {
                            settings.success(xhr.response)
                        }
                        resolve(xhr.response)
                    }
                }
            })
        }
    })
})();